package com.superzqb.asus.superzqbFragment.superzqbShopSearch;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;

import com.superzqb.asus.superzqb.R;


/**
 * Created by asus on 2017/1/19.
 */

public class MainShopSearch extends Activity {
    private ImageButton back;
    private EditText search;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shop_search);
        initView();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        /*search.setFocusable(false);*/
        search.setOnEditorActionListener(new OnEditorActionListener(){

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                /*判断是否是回车键*/
                //Toast.makeText(MainShopSearch.this,"正在查找，请稍后",Toast.LENGTH_SHORT).show();
                /*if(KeyEvent.KEYCODE_ENTER==actionId){
                    ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(MainShopSearch.this.getCurrentFocus()
                                    .getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
                    if(search.getText().toString().equals("")){
                        Toast.makeText(MainShopSearch.this,"您没有输入任何内容",Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(MainShopSearch.this,"正在查找，请稍后",Toast.LENGTH_SHORT).show();
                    }
                }*/
                if(EditorInfo.IME_ACTION_SEARCH==actionId||(event!=null&&event.getKeyCode()==KeyEvent.KEYCODE_ENTER)){
                    if(search.getText().toString().equals("")){
                        Toast.makeText(MainShopSearch.this,"您没有输入任何内容",Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(MainShopSearch.this,"正在查找，请稍后",Toast.LENGTH_SHORT).show();
                    }
                }
                return false;
            }
        });


    }

    private void initView() {
        back=(ImageButton)findViewById(R.id.back);
        search=(EditText)findViewById(R.id.search);

    }
}
